{% extends 'users/base.html' %}
{% load helpers %}
{% load form_helpers %}

{% block usercontent %}
    <form method="post" action="" class="h-100 vstack">
        {% csrf_token %}
        <div class="row align-content-start flex-fill">
            {% if preferences %}
                <div class="col-md-8 offset-md-2">
                    <div class="card">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>
                                            <input class="form-check-input nb-form-check-input-sm mt-2 toggle"
                                                   title="Toggle all"
                                                   type="checkbox">
                                        </th>
                                        <th>Preference</th>
                                        <th>Value</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for key, value in preferences.items %}
                                        <tr>
                                            <td class="nb-w-0">
                                                <input class="form-check-input nb-form-check-input-sm mt-2"
                                                       name="pk"
                                                       type="checkbox"
                                                       value="{{ key }}">
                                            </td>
                                            <td><samp>{{ key }}</samp></td>
                                            <td><samp>{{ value }}</samp></td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-danger mb-16">
                        <span class="mdi mdi-trash-can-outline me-4" aria-hidden="true"></span><!--
                        -->Clear Selected
                    </button>
                </div>
            {% else %}
                <h3 class="col-md-8 offset-md-2 mb-16 text-center text-secondary">No preferences found</h3>
            {% endif %}
            <div class="col-md-8 offset-md-2">
                {% if form.non_field_errors %}
                    <div class="card border-danger">
                        <div class="card-header bg-danger-subtle border-danger text-body">
                            <strong>Errors</strong>
                        </div>
                        <div class="card-body">
                            {{ form.non_field_errors }}
                        </div>
                    </div>
                {% endif %}
                <div class="card">
                    <div class="card-header"><strong>Preference Settings</strong></div>
                    <div class="card-body">
                        {% render_field form.timezone %}
                    </div>
                </div>
            </div>
        </div>
        <div class="nb-form-sticky-footer">
            <button type="submit" name="_update_preference_form" class="btn btn-primary">
                <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                -->Update
            </button>
        </div>
    </form>
{% endblock %}
